import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import { mesh } from "./mesh.js";
import { mesh1 } from "./mesh1.js";

const scene = new THREE.Scene();
scene.add(mesh);
scene.add(mesh1);

/**
 * 添加光源
 * 部分材质依赖光源才能看到mesh
 * 例如MeshBasicMaterial不依赖光源，MeshLambertMaterial和MeshPhongMaterial依赖光源
 * */
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(300, 300, 300);
scene.add(directionalLight);
const ambientLight = new THREE.AmbientLight(0x404040, 1);
scene.add(ambientLight);

// 创建相机
const width = window.innerWidth;
const height = window.innerHeight;
const camera = new THREE.PerspectiveCamera(60, width / height, 1, 10000);
// 设置相机位置,如果不设置相机位置，默认位置在(0, 0, 0)，看不到物体
camera.position.set(1000, 1000, 1000);
camera.lookAt(0, 0, 0);

// 创建渲染器
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 渲染
function render() {
	renderer.render(scene, camera);
	requestAnimationFrame(render);
}
render();

//添加坐标轴辅助器
const axesHelper = new THREE.AxesHelper(500);
scene.add(axesHelper);

//轨道控制器
const controls = new OrbitControls(camera, renderer.domElement);
controls.addEventListener("change", function () {
	renderer.render(scene, camera);
});

//调试工具
const gui = new GUI();
gui.add(mesh.morphTargetInfluences, '0', 0, 1);
gui.add(mesh.morphTargetInfluences, '1', 0, 1);

